from get_url_response import geturl
import lxml.etree as le

if __name__ == '__main__':
    url = 'https://edu.csdn.net/'
    response = geturl(url)

    # get category titles
    div_s = le.HTML(response).xpath('//div[@class="classify_cList"]')
    data_list = []
    for div in div_s:
        # first level category
        category1 = div.xpath('./h3/a/text()')[0]
        # second level category
        category2_s = div.xpath('./div[@class="classify_list"]/span/a/text()')
        data_list.append(
            dict(
                category1 = category1,
                category2 = category2_s,
            )
        )

    for data in data_list:
        print(data.get('category1'))
        for data2 in data.get('category2'):
            print('\t', data2)

